<%@page import="com.stu.utils.PageBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<title>极客之家-新闻管理</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<!-- 分页 -->
<link rel="stylesheet" href="<%=path%>/css/bootstrap-combined.css">
<link rel="stylesheet" href="<%=path%>/css/info_list.css">

</head>

<body>
	<!-- top start -->
	<jsp:include page="top.jsp"></jsp:include>
	<!-- top end -->

	<div class="container-fluid divBlock">



		<%--加载中 start --%> 
		<div id="loading" >Loading...</div>  
		<%--加载中 end --%>
		
		<div class="row cotainer  infoTable">
			<table class="table  table-striped table-bordered">
				<caption class="text-center">
					<header class="toCenter">
						<h1>
							<small> News</small>
						</h1>
						<hr style="width: 100%;">
					</header>
					<div class="">
						<input type="text" name="" id="a_s_title"
							class="admin_news_search_input" placeholder="新闻标题">
						<button class="btn btn-info info_list_search_btn"
							id="admin_search_btn">查询新闻</button>
						<!-- 重新抓取新闻 start -->
						<button class="btn btn-info " data-style="slide-down" data-loading-text="加载ing...." id="admin_news_get">重新抓取</button>
						<!-- 重新抓取新闻 end -->
					</div>
				</caption>
				<thead>
					<tr>
						<td class="  " style="text-align: center;"><input
							type="checkbox" id="checkAllAdminNews" value="">
							<button class="btn btn-warning" id="admin_news_list_delAll_btn">删除</button>
						</td>
						<td class="  " style="text-align: center;">标题</td>
						<td class="  " style="text-align: center;">时间</td>
					</tr>
				</thead>
				<tbody id="admin_news_list_tbody">

				</tbody>


			</table>
		</div>
	</div>


	<!-- js start -->
	<script type="text/javascript" src="<%=path%>/js/admin_news_list.js"></script>

	<script type="text/javascript">  
		$(function() {
			$("#loading").hide();
			var path='<%=path%>';

			refreshAdminNewsTable(path, 1);

			/* 点击新闻删除  */
			$("#admin_news_list_delAll_btn").click(function() {
				var ids = getChecked();
				if (ids.length > 0) {
					$.ajax({
						type : "POST",
						url : path + "/newsAction_deleteNewsByIds.action",
						data : {
							ids : ids,
						},
						dataType : "json",
						success : function(result) {
							if (result.success) {
								alertSuccess("删除数据成功");
								refreshAdminNewsTable(path, 1);
							} else {
								alertError("删除数据失败");
							}
						},
						error:function(){
							alertError("网络连接失败~~");
						}
					}); 
				} else {
					alertError("请选中删除项");
				}
			})

			/* 点击查询  */
			$("#admin_search_btn").click(function() {
				refreshAdminNewsTable(path, 1);
				return false;/* 防止刷新整个页面  */
			})

			/* 全选/取消选中  */
			$("#checkAllAdminNews").bind("click", function() {
				if (this.checked) {
					$("input[type=checkbox]").prop("checked", 'true');
				} else {
					$("input[type=checkbox]").removeAttr("checked");
				}
			});

			
			/* 重新抓取新闻  */
			$("#admin_news_get").click(function() {
				
				$("#loading").show();
				$("#loading").addClass("loading");
				
				$.ajax({
					type : "POST",
					url : path + "/newsAction_saveNews.action",
					data : {
						title : $("#a_s_title").val(),
					},
					dataType : "json",
					success : function(result) {
						if (result.success) {
							alertSuccess("抓取数据成功");
							refreshAdminNewsTable(path, 1);
							$("#loading").hide();
							$("#loading").removeClass("loading");
						} else {
							alertError("抓取数据失败");
							$("#loading").hide();
							$("#loading").removeClass("loading");
						}
					}
				});
			});
			
		});
		
	</script>
	<!--  js end -->

</body>
</html>